package servlet;

import com.google.gson.Gson;
import dao.Impl.StaffsDaoImpl;
import dao.StaffsDao;
import entitl.Staffs;
import util.GsonUtil;
import vo.ResponseData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @Author czl
 * @Date 2024-01-17
 */
@WebServlet("/staffsoAll")
public class staffsoAll extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        StaffsDao staffsDao = new StaffsDaoImpl();
        List<Staffs> list = staffsDao.selectAll();

        ResponseData responseData = new ResponseData();
        responseData.setCode(200);
        responseData.setMsg("success");
        responseData.setData(list);

        String json = GsonUtil.toJson(list);

        resp.setContentType("application/json;charset=utf-8");
        resp.setCharacterEncoding("utf-8");

        PrintWriter out = resp.getWriter();
        out.print(json);

        out.flush();
        out.close();
    }
}
